(function ($) { // to top right away if (window.location.hash) scroll(0, 0); $(window).on('load', function () { // *only* if we have anchor on the url if (window.location.hash) { // void some browsers issue setTimeout(function () { scroll(0, 0); // smooth scroll to the anchor id $('html, body').animate({ scrollTop: $(window.location.hash).offset().top - 100 + 'px' }, 1800, 'swing'); }, 1); } }); // Variables const $scrolled_down_position = 200; // executes when HTML-Document is loaded and DOM is ready $(function () { handleScrolledDownClass(); handleScrollEffects(); $('select.gfield_select').niceSelect(); }); // executes when complete page is fully loaded, including all frames, objects and images $(window).on('load', function () { addPageLoadedClass(); }); // executes on scroll $(window).on('scroll', function () { handleScrolledDownClass(); handleScrollEffects(); }); // executes on resize $(window).on('resize', function () { handleScrolledDownClass(); handleScrollEffects(); }); /* Misc Helpers */ function addPageLoadedClass() { $('body').addClass('page-loaded'); } function handleScrolledDownClass() { var scroll = $(window).scrollTop(); if (scroll >= $scrolled_down_position) { $('body').addClass('scrolled-down'); } else { $('body').removeClass('scrolled-down'); } } function handleScrollEffects() { var window_top = $(window).scrollTop(); var window_height = $(window).height(); $('[data-scroll-effects*="onview"]').each(function () { var el = $(this); var el_top = el.offset().top - (window_height * .9); if (window_top > el_top) { el.addClass('scrolled-into-view'); } }); $('.fade-in-from-top').each(function () { var el = $(this); var el_top = el.offset().top - (window_height * .9); if (window_top > el_top) { el.addClass('scrolled-into-view'); } }); $('[data-scroll-effects*="onpast"]').each(function () { var el = $(this); var el_top = el.offset().top; if (window_top > (el_top - (window_height * .2))) { el.addClass('scrolled-past-75'); } else { el.removeClass('scrolled-past-75'); } if (window_top > (el_top - (window_height * .5))) { el.addClass('scrolled-past'); } else { el.removeClass('scrolled-past'); } if (window_top > (el_top - (window_height * .8))) { el.addClass('scrolled-past-25'); } else { el.removeClass('scrolled-past-25'); } }); } /* Enable Bootstrap Menu Dropdowns on Hover */ const $dropdown = $(".dropdown"); const $dropdownToggle = $(".dropdown-toggle"); const $dropdownMenu = $(".dropdown-menu"); const showClass = "show"; $(window).on("load resize", function () { // Enable dropdown on hover $dropdown.hover( function () { const $this = $(this); $this.addClass(showClass); $this.find($dropdownToggle).attr("aria-expanded", "true"); $this.find($dropdownMenu).addClass(showClass); }, function () { const $this = $(this); $this.removeClass(showClass); $this.find($dropdownToggle).attr("aria-expanded", "false"); $this.find($dropdownMenu).removeClass(showClass); } ); // Make parent menu item clickable (comment out if you don't want parents clickable) $dropdownToggle.click(function () { var location = $(this).attr('href'); window.location.href = location; return false; }); }); })(jQuery); /* Improving Scroll Performance with Passive Event Listeners https://developers.google.com/web/updates/2016/06/passive-event-listeners */ jQuery.event.special.touchstart = { setup: function (_, ns, handle) { this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") }); } }; jQuery.event.special.touchmove = { setup: function (_, ns, handle) { this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") }); } }; jQuery.event.special.wheel = { setup: function (_, ns, handle) { this.addEventListener("wheel", handle, { passive: true }); } }; jQuery.event.special.mousewheel = { setup: function (_, ns, handle) { this.addEventListener("mousewheel", handle, { passive: true }); } };